/*
 * Copyright (c) 2020, 2023, 3044483124@qq.com All rights reserved.
 *
 */
package cn.itcast;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;

/**
 * <p>Project: JavaStudy - Img3
 * <p>Powered by jiangbo On 2023-01-05
 * 20:52:02
 * <p>Created by IntelliJ IDEA
 *
 * @author jiangbo [3044483124@qq.com]
 * @version 1.0
 * @since 8/17
 */
public class Img3 {
    public static void main(String[] args) throws Exception {
        var w = 800;
        var h = 800;
        var i = new BufferedImage(w, h, 2);
        var g = i.createGraphics();
        g.setStroke(new BasicStroke(3f));
        g.setColor(Color.WHITE);
        g.drawRect(0, 0, w - 1, h - 1);
        g.setColor(Color.YELLOW);
        for (int i1 = 1; i1 < w; i1++) {
            g.drawLine(i1, h / 2, i1 + 5, h / 2);
            g.drawLine(w / 2, i1, w / 2, i1 + 5);
            i1 += 15;
        }
        g.setColor(Color.GREEN);
        int xx = 400, yy = 300;//坐标中心
        int angle = 0;//角度
        int cw = 200, ch = 200;//控制圆形的水平直径 垂直直径
        for (int n = 0; n <= 36; n++) {
            int x = xx - (int) (Math.sin(angle * Math.PI / 360) * cw);
            int y = yy - (int) (Math.cos(angle * Math.PI / 360) * ch);
            g.fillOval(x, y, 10, 10);
            angle += 20;
        }
        g.setColor(Color.PINK);
        int x = 1;
        xx = 100;
        for (int n = 0; n <= w; n++) {
            int y = xx - (int) (Math.sin(angle * Math.PI / 360) * 120);
            x = n;
            g.fillOval(y, x, 10, 10);
            g.setColor(Color.ORANGE);
            g.fillOval(x, y, 10, 10);
            angle += 5;
        }
        g.dispose();
        ImageIO.write(i, "png", new File("img3.png"));
        Runtime.getRuntime().exec("cmd /k start img3.png");
    }
}


